/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package amanda_gabriel_isabella_lucivania_monica.View;

import amanda_gabriel_isabella_lucivania_monica.Model.Dao.DaoBaseImpl;
import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Disciplina;
import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Professor;
import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Turma;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Vector;
import javax.swing.DefaultListModel;

/**
 *
 * @author lucy
 */
public class EditarTurmaIG extends javax.swing.JFrame {

    /**
     * Creates new form EditarTurmaIG
     */
    List<Professor> professores = null;
    private DaoBaseImpl daoBaseImpl;

    public EditarTurmaIG(DaoBaseImpl daoBaseImpl) {
        initComponents();
        this.daoBaseImpl = daoBaseImpl;

        jTAno.setEditable(false);
        jTHorario.setEditable(false);
        jTLocal.setEditable(false);
        jTNumeroVagas.setEditable(false);
        jTPeriodo.setEditable(false);
        jCEscolherDisciplina.setEnabled(false);
        jLProfessores.setEnabled(false);


    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("amanda_gabriel_isabella_lucivania_monicaPU").createEntityManager();
        turmaQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT t FROM Turma t");
        turmaList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : turmaQuery.getResultList();
        amanda_gabriel_isabella_lucivania_monicaPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("amanda_gabriel_isabella_lucivania_monicaPU").createEntityManager();
        disciplinaQuery = java.beans.Beans.isDesignTime() ? null : amanda_gabriel_isabella_lucivania_monicaPUEntityManager.createQuery("SELECT d FROM Disciplina d");
        disciplinaList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : disciplinaQuery.getResultList();
        professorTurmaQuery = java.beans.Beans.isDesignTime() ? null : amanda_gabriel_isabella_lucivania_monicaPUEntityManager.createQuery("SELECT p FROM ProfessorTurma p");
        professorTurmaList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : professorTurmaQuery.getResultList();
        jDProfessores = new javax.swing.JDialog();
        jScrollPane2 = new javax.swing.JScrollPane();
        jLTodosProfessores = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jBSelecionaProfessor = new javax.swing.JButton();
        professorQuery = java.beans.Beans.isDesignTime() ? null : amanda_gabriel_isabella_lucivania_monicaPUEntityManager.createQuery("SELECT p FROM Professor p");
        professorList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : professorQuery.getResultList();
        jDSucesso = new javax.swing.JDialog();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jBSim = new javax.swing.JButton();
        jBNao = new javax.swing.JButton();
        jBCancelar = new javax.swing.JButton();
        jBEditar = new javax.swing.JButton();
        jPPainelListarTurmas = new javax.swing.JPanel();
        jSPListaProfessores = new javax.swing.JScrollPane();
        jLListarTurmas = new javax.swing.JList();
        jPanel1 = new javax.swing.JPanel();
        jTAno = new javax.swing.JTextField();
        jLAno = new javax.swing.JLabel();
        jTPeriodo = new javax.swing.JTextField();
        jLPeriodo = new javax.swing.JLabel();
        jTLocal = new javax.swing.JTextField();
        jLLocal = new javax.swing.JLabel();
        jTHorario = new javax.swing.JTextField();
        jLHorario = new javax.swing.JLabel();
        jTNumeroVagas = new javax.swing.JTextField();
        jLNumeroVagas = new javax.swing.JLabel();
        jCEscolherDisciplina = new javax.swing.JComboBox();
        jLEscolherDisciplina = new javax.swing.JLabel();
        jLPeriod = new javax.swing.JLabel();
        jLVagas = new javax.swing.JLabel();
        jLVincularDisciplinaTurma = new javax.swing.JLabel();
        jLVincularProfessorTurma = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jLProfessores = new javax.swing.JList();
        jBInserir = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jBSalvar = new javax.swing.JButton();

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jDProfessores.setMinimumSize(new java.awt.Dimension(300, 300));

        jScrollPane2.setViewportView(jLTodosProfessores);

        jLabel1.setText("Selecione um professor:");

        jBSelecionaProfessor.setText("OK");
        jBSelecionaProfessor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSelecionaProfessorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDProfessoresLayout = new javax.swing.GroupLayout(jDProfessores.getContentPane());
        jDProfessores.getContentPane().setLayout(jDProfessoresLayout);
        jDProfessoresLayout.setHorizontalGroup(
            jDProfessoresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDProfessoresLayout.createSequentialGroup()
                .addGroup(jDProfessoresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jDProfessoresLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jDProfessoresLayout.createSequentialGroup()
                        .addGap(77, 77, 77)
                        .addComponent(jLabel1))
                    .addGroup(jDProfessoresLayout.createSequentialGroup()
                        .addGap(136, 136, 136)
                        .addComponent(jBSelecionaProfessor, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(31, Short.MAX_VALUE))
        );
        jDProfessoresLayout.setVerticalGroup(
            jDProfessoresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDProfessoresLayout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jBSelecionaProfessor)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jDSucesso.setMinimumSize(new java.awt.Dimension(400, 176));

        jLabel6.setText("Turma editada com sucesso!");

        jLabel7.setText("Deseja editar novamente?");

        jBSim.setText("Sim");
        jBSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSimActionPerformed(evt);
            }
        });

        jBNao.setText("Não");
        jBNao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDSucessoLayout = new javax.swing.GroupLayout(jDSucesso.getContentPane());
        jDSucesso.getContentPane().setLayout(jDSucessoLayout);
        jDSucessoLayout.setHorizontalGroup(
            jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDSucessoLayout.createSequentialGroup()
                .addGroup(jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jDSucessoLayout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addGroup(jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6)))
                    .addGroup(jDSucessoLayout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(jBSim, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(jBNao, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(58, Short.MAX_VALUE))
        );
        jDSucessoLayout.setVerticalGroup(
            jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDSucessoLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBSim)
                    .addComponent(jBNao))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Alterar dados da Turma");

        jBCancelar.setText("Cancelar");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        jBEditar.setText("Editar");
        jBEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEditarActionPerformed(evt);
            }
        });

        jPPainelListarTurmas.setBorder(javax.swing.BorderFactory.createTitledBorder("Por favor, selecione uma turma a qual deseja editar:"));

        jSPListaProfessores.setViewportView(jLListarTurmas);

        javax.swing.GroupLayout jPPainelListarTurmasLayout = new javax.swing.GroupLayout(jPPainelListarTurmas);
        jPPainelListarTurmas.setLayout(jPPainelListarTurmasLayout);
        jPPainelListarTurmasLayout.setHorizontalGroup(
            jPPainelListarTurmasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPPainelListarTurmasLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jSPListaProfessores, javax.swing.GroupLayout.PREFERRED_SIZE, 439, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(142, 142, 142))
        );
        jPPainelListarTurmasLayout.setVerticalGroup(
            jPPainelListarTurmasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPPainelListarTurmasLayout.createSequentialGroup()
                .addComponent(jSPListaProfessores, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 8, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Por favor, insira os novos dados abaixo:"));
        jPanel1.setToolTipText("Exemplo");

        jLAno.setText("Ano:");

        jLPeriodo.setText("Período:");

        jTLocal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTLocalActionPerformed(evt);
            }
        });

        jLLocal.setText("Local:");

        jLHorario.setText("Horário:");

        jTNumeroVagas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTNumeroVagasActionPerformed(evt);
            }
        });

        jLNumeroVagas.setText("Número de Vagas:");

        jLEscolherDisciplina.setText("Escolha a Disciplina :");

        jLPeriod.setText("período");

        jLVagas.setText("vagas");

        jLVincularDisciplinaTurma.setText("Vincular Disciplina/Turma:");

        jLVincularProfessorTurma.setText("Professores vinculados à Turma:");

        jScrollPane1.setViewportView(jLProfessores);

        jBInserir.setText("Inserir");
        jBInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBInserirActionPerformed(evt);
            }
        });

        jButton2.setText("Remover");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLHorario)
                            .addComponent(jLLocal)
                            .addComponent(jLPeriodo)
                            .addComponent(jLAno))
                        .addGap(172, 172, 172))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLNumeroVagas)
                        .addGap(104, 104, 104)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jTNumeroVagas, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLVagas))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jTPeriodo, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
                            .addComponent(jTAno, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLPeriod))
                    .addComponent(jTLocal, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTHorario, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(39, 39, 39)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLEscolherDisciplina)
                        .addGap(38, 38, 38)
                        .addComponent(jCEscolherDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLVincularDisciplinaTurma)
                    .addComponent(jLVincularProfessorTurma)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                            .addComponent(jBInserir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(63, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLAno)
                            .addComponent(jTAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLVincularDisciplinaTurma)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLPeriodo)
                    .addComponent(jTPeriodo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLPeriod)
                    .addComponent(jLEscolherDisciplina)
                    .addComponent(jCEscolherDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLLocal, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTLocal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTHorario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLHorario, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jLVincularProfessorTurma)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLNumeroVagas)
                        .addComponent(jTNumeroVagas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLVagas))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jBInserir)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2)))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        jBSalvar.setText("Salvar");
        jBSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSalvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPPainelListarTurmas, javax.swing.GroupLayout.PREFERRED_SIZE, 545, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jBSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jBEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jBCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(51, 51, 51))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPPainelListarTurmas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBEditar)
                    .addComponent(jBCancelar))
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBSalvar)
                .addGap(294, 294, 294))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
        setVisible(false);
    }//GEN-LAST:event_jBCancelarActionPerformed

    private void jTNumeroVagasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTNumeroVagasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTNumeroVagasActionPerformed

    private void jTLocalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTLocalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTLocalActionPerformed

    private void jBEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEditarActionPerformed
        Turma turma = (Turma) jLListarTurmas.getSelectedValue();

        jTAno.setEditable(true);
        jTHorario.setEditable(true);
        jTLocal.setEditable(true);
        jTNumeroVagas.setEditable(true);
        jTPeriodo.setEditable(true);
        jCEscolherDisciplina.setEnabled(true);
        jLProfessores.setEnabled(true);

        jTAno.setText(turma.getAno() + "");
        jTHorario.setText(turma.getHorario());
        jTLocal.setText(turma.getLugar());
        jTNumeroVagas.setText(turma.getNumeroVagas() + "");
        jTPeriodo.setText(turma.getPeriodo() + "");
        Disciplina disciplina = (Disciplina) jCEscolherDisciplina.getSelectedItem();

        jLProfessores.setModel(new DefaultListModel());
        List<String> parametros = new ArrayList<String>();
        List<String> objetos = new ArrayList<String>();
        parametros.add("idTurma");
        objetos.add(turma.getId() + "");
        professores = turma.getProfessor();
        Vector objetos2 = new Vector();
        for (Professor objeto : professores) {

            objetos2.addElement(objeto);
        }
        jLProfessores.setListData(objetos2);
        jLProfessores.setVisible(true);

    }//GEN-LAST:event_jBEditarActionPerformed

    private void jBSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSalvarActionPerformed
        Turma turma = (Turma) jLListarTurmas.getSelectedValue();

        turma.setAno(Integer.parseInt(jTAno.getText()));
        turma.setDisciplina((Disciplina) jCEscolherDisciplina.getSelectedItem());
        turma.setHorario(jTHorario.getText());
        turma.setLugar(jTLocal.getText());
        turma.setNumeroVagas(Integer.parseInt(jTNumeroVagas.getText()));
        turma.setPeriodo(Integer.parseInt(jTPeriodo.getText()));
        turma.setProfessor(professores);

        daoBaseImpl.update(turma);

        jDSucesso.setVisible(true);
    }//GEN-LAST:event_jBSalvarActionPerformed

    private void jBInserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBInserirActionPerformed
        jDProfessores.setVisible(true);
    }//GEN-LAST:event_jBInserirActionPerformed

    private void jBSelecionaProfessorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSelecionaProfessorActionPerformed
        Professor professor = (Professor) jLTodosProfessores.getSelectedValue();
        if(!professores.contains(professor)){
            professores.add(professor);
            Vector objetos2 = new Vector();
            for (Professor objeto : professores) {

                objetos2.addElement(objeto);
            }
            jLProfessores.setListData(objetos2);
            jLProfessores.setVisible(true);
            
        }
        jDProfessores.dispose();
    }//GEN-LAST:event_jBSelecionaProfessorActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        int index = jLProfessores.getSelectedIndex();
        professores.remove(index);
        jLProfessores.setModel(new DefaultListModel());

        Vector objetos2 = new Vector();
        for (Professor objeto : professores) {

            objetos2.addElement(objeto);
        }
        jLProfessores.setListData(objetos2);
        jLProfessores.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jBSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSimActionPerformed

        jDSucesso.dispose();
        jTAno.setEditable(false);
        jTHorario.setEditable(false);
        jTLocal.setEditable(false);
        jTNumeroVagas.setEditable(false);
        jTPeriodo.setEditable(false);
        jCEscolherDisciplina.setEnabled(false);
        jLProfessores.setEnabled(false);
    }//GEN-LAST:event_jBSimActionPerformed

    private void jBNaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBNaoActionPerformed
        setVisible(false);
        jDSucesso.dispose();
    }//GEN-LAST:event_jBNaoActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.persistence.EntityManager amanda_gabriel_isabella_lucivania_monicaPUEntityManager;
    private java.util.List<amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Disciplina> disciplinaList;
    private javax.persistence.Query disciplinaQuery;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JButton jBCancelar;
    private javax.swing.JButton jBEditar;
    private javax.swing.JButton jBInserir;
    private javax.swing.JButton jBNao;
    private javax.swing.JButton jBSalvar;
    private javax.swing.JButton jBSelecionaProfessor;
    private javax.swing.JButton jBSim;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jCEscolherDisciplina;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JDialog jDProfessores;
    private javax.swing.JDialog jDSucesso;
    private javax.swing.JLabel jLAno;
    private javax.swing.JLabel jLEscolherDisciplina;
    private javax.swing.JLabel jLHorario;
    private javax.swing.JList jLListarTurmas;
    private javax.swing.JLabel jLLocal;
    private javax.swing.JLabel jLNumeroVagas;
    private javax.swing.JLabel jLPeriod;
    private javax.swing.JLabel jLPeriodo;
    private javax.swing.JList jLProfessores;
    private javax.swing.JList jLTodosProfessores;
    private javax.swing.JLabel jLVagas;
    private javax.swing.JLabel jLVincularDisciplinaTurma;
    private javax.swing.JLabel jLVincularProfessorTurma;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPPainelListarTurmas;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jSPListaProfessores;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTAno;
    private javax.swing.JTextField jTHorario;
    private javax.swing.JTextField jTLocal;
    private javax.swing.JTextField jTNumeroVagas;
    private javax.swing.JTextField jTPeriodo;
    private java.util.List<amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Professor> professorList;
    private javax.persistence.Query professorQuery;
    private java.util.List<amanda_gabriel_isabella_lucivania_monica.View.ProfessorTurma> professorTurmaList;
    private javax.persistence.Query professorTurmaQuery;
    private java.util.List<amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Turma> turmaList;
    private javax.persistence.Query turmaQuery;
    // End of variables declaration//GEN-END:variables
}
